﻿<UserControl x:Class="MMLib.SHotkey.SearchingControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             Background="{DynamicResource VsBrush.Window}"
             Foreground="{DynamicResource VsBrush.WindowText}"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300"
             Name="MyToolWindow" DataContextChanged="MyToolWindow_DataContextChanged">
    <UserControl.Resources>

        <SolidColorBrush x:Key="NormalBrush" Color="#FFF" />

        <LinearGradientBrush x:Key="HorizontalNormalBrush" StartPoint="0,0" EndPoint="1,0">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#CCC" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="LightBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#EEE" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="HorizontalLightBrush" StartPoint="0,0" EndPoint="1,0">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#EEE" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
            <GradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#FFF" Offset="0.0"/>
                    <GradientStop Color="#AAA" Offset="1.0"/>
                </GradientStopCollection>
            </GradientBrush.GradientStops>
        </LinearGradientBrush>

        <SolidColorBrush  x:Key="PressedBrush" Color="#7f8c8d" />

        <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />

        <SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" />

        <SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" />

        <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="#7f8c8d" />

        <!-- Border Brushes -->

        <SolidColorBrush x:Key="NormalBorderBrush" Color="#CCC" />

        <SolidColorBrush x:Key="HorizontalNormalBorderBrush" Color="#CCC" />

        <SolidColorBrush x:Key="DefaultedBorderBrush" Color="#777" />

        <SolidColorBrush  x:Key="PressedBorderBrush" Color="#444" />

        <SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" />

        <SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />

        <SolidColorBrush x:Key="LightBorderBrush" Color="#AAA" />

        <!-- Miscellaneous Brushes -->
        <SolidColorBrush x:Key="GlyphBrush" Color="#444" />

        <SolidColorBrush x:Key="LightColorBrush" Color="#DDD" />

        <Style x:Key="ToolBarButtonBaseStyle" TargetType="{x:Type ButtonBase}">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ButtonBase}">
                        <Border 
                              x:Name="Border"  
                              BorderThickness="1"
                              Background="Transparent"
                              BorderBrush="Transparent">
                            <ContentPresenter 
            Margin="2"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            RecognizesAccessKey="True"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsKeyboardFocused" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="{StaticResource SelectedBackgroundBrush}" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource SolidBorderBrush}" />
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource  VsBrush.CommandBarHover}" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource  VsBrush.CommandBarHover}" />
                            </Trigger>
                            <Trigger Property="IsPressed" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource  VsBrush.CommandBarHover}" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource  VsBrush.CommandBarHover}" />
                            </Trigger>
                            <Trigger Property="CheckBox.IsChecked" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource  VsBrush.CommandBarHover}" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                                <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="{x:Static ToolBar.ButtonStyleKey}" 
       BasedOn="{StaticResource ToolBarButtonBaseStyle}"
       TargetType="{x:Type Button}"/>
        <Style x:Key="{x:Static ToolBar.ToggleButtonStyleKey}" 
       BasedOn="{StaticResource ToolBarButtonBaseStyle}"
       TargetType="{x:Type ToggleButton}"/>
        <Style x:Key="{x:Static ToolBar.CheckBoxStyleKey}" 
       BasedOn="{StaticResource ToolBarButtonBaseStyle}"
       TargetType="{x:Type CheckBox}"/>
        <Style x:Key="{x:Static ToolBar.RadioButtonStyleKey}"
       BasedOn="{StaticResource ToolBarButtonBaseStyle}"
       TargetType="{x:Type RadioButton}"/>

        <Style x:Key="{x:Type ToolBar}" TargetType="{x:Type ToolBar}">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ToolBar}">
                        <Border x:Name="Border"  
                                  CornerRadius="2" 
                                  BorderThickness="1"
                                  Background="{DynamicResource VsBrush.Window}">
                            <Grid>
                                <ToolBarPanel x:Name="PART_ToolBarPanel"
                                          IsItemsHost="true"
                                          Margin="0,1,2,2" />
                                <Thumb x:Name="ToolBarThumb"
                                       Visibility="Collapsed"
                                        Width="10"/>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="{x:Type DataGridCell}">
            <Setter Property="Background" 
                    Value="{DynamicResource VsBrush.Window}" />
            <Setter Property="Foreground" 
                    Value="{DynamicResource VsBrush.WindowText}" />
            <Setter Property="Opacity" Value="0.9" />
            <Setter Property="BorderThickness" Value="0"/>

            <Style.Triggers>
                <Trigger Property="IsSelected"
                        Value="True">
                    <Setter Property="Background"
                        Value="#3498db" />
                    <Setter Property="Opacity" Value="1" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="DataGridRow">
            <Style.Triggers>
                <Trigger Property="IsSelected"
                        Value="True">
                    <Setter Property="Background"
                        Value="#3498db" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="Height" Value="25" />
            <Setter Property="Padding" Value="5" />
            <Setter Property="BorderThickness" Value="0,0,1,1" />
            <Setter Property="BorderBrush" Value="{DynamicResource VsBrush.CommandBarMenuSeparator}" />
            <Setter Property="Background" 
                    Value="{DynamicResource VsBrush.Window}" />
            <Setter Property="Foreground" 
                    Value="{DynamicResource VsBrush.WindowText}" />
        </Style>

        <Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBoxBase}">
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="MinWidth" Value="120"/>
            <Setter Property="MinHeight" Value="20"/>
            <Setter Property="AllowDrop" Value="true"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TextBoxBase}">
                        <Border 
                              Name="Border"
                              CornerRadius="0" 
                              Padding="2"
                               Background="{DynamicResource VsBrush.SearchBoxBackground}"
                               BorderBrush="{DynamicResource VsBrush.CommandBarMenuSeparator}"
                              BorderThickness="1" >
                            <ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <ToolBar Background="{DynamicResource VsBrush.Window}" >
            <CheckBox IsChecked="{Binding Path=SearchByShortcut}" 
                      Checked="CheckBox_Checked"
                      x:Name="chkSearchByShortcut" Unchecked="CheckBox_Checked">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Stretch">
                    <Image x:Name="checkedImg" Source="/SHotkey;component/Resources/KeyList.png" Width="20" Height="20" />
                    <Image x:Name="uncheckedImg" Source="/SHotkey;component/Resources/List.png" Width="20" Height="20" />
                    <TextBlock x:Name="checkText" Text="Search by name" Margin="2,0" Foreground="{DynamicResource VsBrush.ButtonText}" />
                </StackPanel>
            </CheckBox>
            <Button Click="Button_Click" ToolTip="Open keyboard settings.">
                <Image Source="/SHotkey;component/Resources/Settings.png" Width="20" Height="20" />
            </Button>
        </ToolBar>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Label Margin="5,1" Content="Search:"  Foreground="{DynamicResource VsBrush.CaptionText}" />
            <TextBox Grid.Column="1" Margin="1,1,2,1"
                     Background="{DynamicResource VsBrush.SearchBoxBackground}"
                     BorderBrush="{DynamicResource VsBrush.ActiveBorder}"
                     Text="{Binding Path=SearchingString, UpdateSourceTrigger=PropertyChanged}"
                     x:Name="txtSearch" PreviewKeyDown="txtSearch_PreviewKeyDown" />
        </Grid>
        <DataGrid Margin="2" Grid.Row="2" ItemsSource="{Binding Path=ItemsSource}" AutoGenerateColumns="False" IsReadOnly="True" PreviewKeyDown="DataGrid_PreviewKeyDown"
                  BorderThickness="1"                  
                  BorderBrush="{DynamicResource VsBrush.CommandBarMenuSeparator}"
                  RowHeaderWidth="0" 
                  x:Name="dataGrid"
                  HorizontalGridLinesBrush="{DynamicResource ResourceKey=VsBrush.GridLine}"
                  VerticalGridLinesBrush="{DynamicResource ResourceKey=VsBrush.GridLine}"
                  HeadersVisibility="Column"
                  Foreground="{DynamicResource VsBrush.WindowText}"
                  RowBackground="{DynamicResource  VsBrush.CommandBarHover}"
                  Background="{DynamicResource VsBrush.Window}" SelectionMode="Single" CanUserResizeRows="False">
            <DataGrid.Columns>
                <DataGridTextColumn ClipboardContentBinding="{x:Null}" Header="Name" 
                                    Binding="{Binding Path=Name}" Width="*"/>
                <DataGridTextColumn ClipboardContentBinding="{x:Null}" Header="Shortcut" 
                                    MinWidth="100" Binding="{Binding Path=Shortcut}"/>
            </DataGrid.Columns>
        </DataGrid>
        
        <Grid Grid.Row="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Label Content="{Binding ElementName=dataGrid, Path=SelectedItem}"
                   Foreground="{DynamicResource VsBrush.WindowText}"
                   Opacity="0.8"/>
        </Grid>
    </Grid>
</UserControl>
